package com.iot.user.controller;

import com.iot.commonutils.utils.Result;
import com.iot.user.entity.User;
import com.iot.user.service.UserListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userList")
public class UserListController {
    @Autowired
    private UserListService userListService;

    /**
     * 展示用户列表
     */
    @PostMapping("/showUserList")
    public Result showUserList(@RequestBody User vo) {
        return userListService.showUserList(vo);
    }

    /**
     * 新增用户
     *
     * @param user
     * @return
     */

    @PostMapping("/addUserList")
    public Result addUserList(@RequestBody User user) {
        return userListService.addUserList(user);
    }

    /**
     * 删除用户
     *
     * @param id
     * @return 注:前端用字段的形式传给id
     */
    @DeleteMapping("deleteUser/{id}")
    public Result deleteUserList(@PathVariable("id") String id) {
        return userListService.deleteUserList(id);
    }

    /**
     * 修改用户信息
     *
     * @param user
     * @return
     */
    @PostMapping("/changeUserList")
    public Result changeUserList(@RequestBody User user) {
        return userListService.changeUserList(user);
    }

    /**
     * 根据用户名模糊查询
     *
     * @param name
     * @return
     */
    @PostMapping("/fuzzyUserList")
    public Result fuzzyUserList(@RequestParam("name") String name) {
        return userListService.fuzzyUserList(name);
    }

    /**
     * 给用户分配角色
     *
     * @param roleId
     * @return
     */
    @PostMapping("/updateUserRole")
    public Result roleUserList(@RequestParam("userId") String userId, @RequestParam("roleId") String roleId) {

        return userListService.roleUserList(userId, roleId);
    }


}
